package com.d0318;

public class SellTickTest extends Thread {
    public SellTickTest(String name){
        super(name);

    }
    static int tick=20;
    static Object ob=new Object();

    @Override
    public void run() {
        while (tick>0){
            synchronized (ob){
                if(tick>0){
                    System.out.println(Thread.currentThread().getName()+"卖出"+tick+"号票");
                    tick--;
                }else {
                    System.out.println("没票了");
                }
            }
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        SellTickTest s1=new SellTickTest("一号窗口");
        SellTickTest s2=new SellTickTest("二号窗口");
        SellTickTest s3=new SellTickTest("三号窗口");
        s1.start();
        s2.start();
        s3.start();
    }
}
